package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.vo.FeedbackDetailVO;
import com.example.computer_exam_training_sys.vo.FeedbackListVO;
import com.example.computer_exam_training_sys.vo.FeedbackResponseVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FeedbackVOMapper {
    // 反馈列表（带用户名、课程名、状态等）
    @Select("SELECT f.feedback_id, f.user_id AS userId, f.content, f.contact, f.create_time, u.username, c.course_name, f.feedback_type, f.status " +
            "FROM feedbacks f " +
            "LEFT JOIN users u ON f.user_id = u.user_id " +
            "LEFT JOIN courses c ON f.course_id = c.course_id ")
    List<FeedbackListVO> selectFeedbackList();

    // 反馈详情（带用户、课程、所有回复等）
    @Select("SELECT f.feedback_id, f.user_id AS userId, f.content,f.contact, f.create_time, u.username, f.contact, c.course_name, f.feedback_type, f.status, f.reply_content, f.reply_time " +
            "FROM feedbacks f " +
            "LEFT JOIN users u ON f.user_id = u.user_id " +
            "LEFT JOIN courses c ON f.course_id = c.course_id " +
            "WHERE f.feedback_id = #{feedbackId}")
    FeedbackDetailVO selectFeedbackDetail(@Param("feedbackId") Integer feedbackId);

    // 某反馈的所有回复
    @Select("SELECT r.*, a.admin_id, u.username AS adminName FROM feedback_response r " +
            "LEFT JOIN admins a ON r.admin_id = a.admin_id " +
            "LEFT JOIN users u ON a.user_id = u.user_id " +
            "WHERE r.feedback_id = #{feedbackId}")
    List<FeedbackResponseVO> selectFeedbackResponses(@Param("feedbackId") Integer feedbackId);

    // 根据用户id查询反馈列表
    @Select("SELECT f.feedback_id, f.user_id AS userId, f.content, f.contact, f.create_time, u.username, c.course_name, f.feedback_type, f.status " +
            "FROM feedbacks f " +
            "LEFT JOIN users u ON f.user_id = u.user_id " +
            "LEFT JOIN courses c ON f.course_id = c.course_id " +
            "WHERE f.user_id = #{userId}")
    List<FeedbackListVO> selectFeedbackListByUserId(@Param("userId") Integer userId);
}
